<?php
require_once ('PHPExcel/Classes/PHPExcel.php');

$objReader = PHPExcel_IOFactory::createReader('Excel5');

$objPHPExcel = $objReader->load('datapic.xls');

foreach ($objPHPExcel->getSheet(0)->getDrawingCollection() as $drawing) {
    if ($drawing instanceof PHPExcel_Worksheet_MemoryDrawing) {
        ob_start();
        call_user_func(
            $drawing->getRenderingFunction(),
            $drawing->getImageResource()
        );
        $imageContents = ob_get_contents();
        
        ob_end_clean();
        
        
        //echo $imageContents;
        
    }
}

//number picture

$numImg = $objPHPExcel->getSheet(0)->getDrawingCollection()->count();
echo  $numImg;

//
//foreach ($objPHPExcel->getSheet(0)->getDrawingCollection() as $i => $drawing) {
//    $filename = $drawing->getPath();
//    $imagesize = getimagesize($filename);
//
//    switch ($imagesize[2]) {
//    
//    case 1:
//        $image = imagecreatefromgif($filename);
//        imagegif($image, "$i.gif");
//        break;
//        
//    case 2:
//        $image = imagecreatefromjpeg($filename);
//        imagejpeg($image, "$i.jpeg");
//        break;
//        
//    case 3:
//        $image = imagecreatefrompng($filename);
//        imagepng($image, "$i.png");
//        break;
//        
//    default:
//        continue 2;
//        
//    }
//}

$index = '0';

foreach ($objPHPExcel->getSheet(0)->getDrawingCollection() as $drawing) {
    // $drawing->getCoordinates();

    // we have an ordinary drawing (case xlsx)
    if ($drawing instanceof PHPExcel_Worksheet_Drawing) {

        $filename = $drawing->getPath();

        copy($filename, 'images/' . $drawing->getIndexedFilename());

    // we have a memory drawing (case xls)
    } else if ($drawing instanceof PHPExcel_Worksheet_MemoryDrawing) {

        $image = $drawing->getImageResource();

        // save image to disk
        $renderingFunction = $drawing->getRenderingFunction();
        
        
        switch ($renderingFunction) {
        
        case PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG:
            imagejpeg($image, 'images/' . $index.'.jpg');
            break;
            
        case PHPExcel_Worksheet_MemoryDrawing::RENDERING_GIF:
            imagegif($image, 'images/' . $index.'.gif');
            break;
            
        case PHPExcel_Worksheet_MemoryDrawing::RENDERING_PNG:
        case PHPExcel_Worksheet_MemoryDrawing::RENDERING_DEFAULT:
            imagepng($image, 'images/' . $index.'.png');
            break;
        }
    }
    
    $index++;
}

?>